home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1992 June: ROMin Holiday / ADC Developer CD (1992-06) (''ROMin Holiday'')_iso / Developer Connection - 06-1992.iso / Development Platforms / Apple II / Apple II Sample Code / MPW IIGS SC / SC.024.Teach / teach.aii / uwindow.aii < prev   
Encoding:
Text File  |  1990-06-24  |  16.0 KB  |  1,044 lines  |  [TEXT/MPS ]

  1. ***********************************************************************
  2. *
  3. * teach uwindow.aii -- Version 3.0
  4. *
  5. * Copyright (c)
  6. * Apple Computer, Inc.  1986-1990
  7. * All Rights Reserved.
  8. *
  9. * Developer Technical Support Apple II Sample Code
  10. *
  11. * This file contains the code which implements  
  12. * windows in the Teach program.
  13. *
  14. ***********************************************************************
  15.  
  16.     case  on
  17.     longi on
  18.     longa on
  19.  
  20.     INCLUDE 'e16.types'
  21.     INCLUDE 'm16.control'
  22.     INCLUDE 'e16.gsos'
  23.     INCLUDE 'm16.gsos'
  24.     INCLUDE 'm16.memory'
  25.     INCLUDE 'm16.quickdraw'
  26.     INCLUDE 'e16.resources'
  27.     INCLUDE 'e16.stdfile'
  28.     INCLUDE 'm16.stdfile'
  29.     INCLUDE 'e16.textedit'
  30.     INCLUDE 'm16.textedit'
  31.     INCLUDE 'm16.util2'
  32.     INCLUDE 'm16.window'
  33.     INCLUDE 'teach.equ'
  34.  
  35. ***********************************************************************
  36. *
  37. * smartGetWTitle
  38. *
  39. * This function returns a pointer to the window title pascal string.
  40. * This is a little more complicated than it used to be, given that
  41. * NewWindow2 clones    the string for the window into an unlocked handle.
  42. * GetWTitle returns    a handle with the hi-bit set (to distinguish it
  43. * from a reguler pointer).  If the hi-bit is set, then we want to
  44. * dereference the handle to a pointer, and return that instead.
  45. *
  46.     EXPORT smartGetWTitle
  47. smartGetWTitle    PROC
  48.  
  49.     DefineStack
  50.  
  51. saveDPage    word
  52. returnAddr    word
  53.  
  54. wptr    long    ;Parameters.
  55. wtitle    long    ;Result.
  56.  
  57. ******************
  58.  
  59.     phd    ;Save directPage register.
  60.     tsc    ;Set directPage register.
  61.     tcd
  62.  
  63.     pha    ;Result space.
  64.     pha
  65.     pei wptr+2    ;wtitle is result space
  66.     pei wptr
  67.     _GetWTitle
  68.     pla
  69.     sta wtitle
  70.     pla
  71.     sta wtitle+2
  72.     bpl exit
  73.  
  74.     ldy #2
  75.     lda [wtitle],y
  76.     tax
  77.     lda [wtitle]
  78.     sta wtitle
  79.     stx wtitle+2
  80.  
  81. exit    pld    ;Restore directPage    register.
  82.     plx    ;Save return address.
  83.     pla    ;Remove passed parameters.
  84.     pla
  85.     phx    ;Restore return address and return.
  86.     rts
  87.  
  88.     ENDP
  89.  
  90. ***********************************************************************
  91. *
  92. * drawThisWindow --    called from the tools (via JSL)
  93. *
  94. * This routine draws the contents of all the windows.
  95. *
  96.     EXPORT drawThisWindow
  97. drawThisWindow    PROC
  98.  
  99.     pha
  100.     pha
  101.     _GetPort
  102.     _DrawControls
  103.     rtl
  104.  
  105.     ENDP
  106.  
  107. ***********************************************************************
  108. *
  109. * doCloseTop
  110. *
  111. * This routine closes the topmost window.
  112. *
  113.     EXPORT doCloseTop
  114. doCloseTop    PROC
  115.  
  116.     pha    ;GetWRefCon result space
  117.     pha
  118.     pha    ;FrontWindow result    space
  119.     pha
  120.     _FrontWindow
  121.     _GetWRefCon
  122.     lda 1,s
  123.     ora 3,s
  124.     beq null    ;Stuff on stack will be
  125. *        ;result space for FrontWindow
  126.  
  127.     _DisposeHandle    ;Get rid of the pathname handle
  128.     pha    ;that we keep in the refCon.
  129.     pha    ;Result space for FrontWindow
  130.  
  131. null    _FrontWindow
  132.     _CloseWindow
  133.  
  134.     rts
  135.  
  136.     ENDP
  137.  
  138. ***********************************************************************
  139. *
  140. * PutFileIntoWindow
  141. *
  142. * This routine opens the specified file, reads its contents    in and sets
  143. * the text of the text edit control of the top window to that text.
  144. *
  145.     EXPORT putFileIntoWindow
  146. putFileIntoWindow    PROC
  147.     import userID
  148.  
  149.     DefineStack
  150.  
  151. theHndl    long    ;Must be at 1,s
  152. c1ptr    long
  153.  
  154. saveDPage    word
  155. returnAddr    word
  156.  
  157. c1hndl    long
  158.  
  159. ******************
  160.  
  161.     phd    ;Save directPage register.
  162.     pha    ;Make space for locals.
  163.     pha
  164.     pha
  165.     pha
  166.     tsc    ;Set directPage register.
  167.     tcd
  168.  
  169.     pei c1hndl+2    ;Lock down the passed handle.
  170.     pei c1hndl
  171.     _HLock
  172.  
  173.     ldy #2    ;Dereference the handle and skip
  174.     lda [c1hndl],y    ;the C1Output buffer size word.
  175.     tax
  176.     lda [c1hndl]
  177.     clc
  178.     adc #2
  179.     bcc aa
  180.     inx
  181. aa    sta c1ptr
  182.     stx c1ptr+2
  183.  
  184.     sta obpathname    ;Set up the openBlock
  185.     stx obpathname+2
  186.     lda #0
  187.     sta obrequestAccess
  188.     sta obresourceNumber
  189.     sta oboptionList
  190.     sta oboptionList+2
  191.     _OpenGS openBlock    ;Open the file.
  192.     bcc ab
  193.     jsr doErrorWindow
  194.     brl unlockExit
  195.  
  196. ab    lda obrefNum    ;Set up closeBlock.
  197.     sta clbrefNum
  198.     sta rbrefNum
  199.  
  200.     PushLong obeof
  201.     PushWord userID
  202.     lda #0
  203.     pha    ;0
  204.     pha    ;NULL
  205.     pha
  206.     _NewHandle    ;Result in theHndl
  207.     bcc ac
  208.     lda #$8E    ;Not enough ram -- close some windows.
  209.     jsr doErrorWindow
  210.     brl closeUnlockExit
  211.  
  212. ac    pei theHndl+2
  213.     pei theHndl
  214.     _HLock
  215.  
  216.     ldy #2    ;Dereference handle    to get
  217.     lda [theHndl],y    ;the readBlock data    buffer.
  218.     sta rbdataBuffer+2
  219.     lda [theHndl]
  220.     sta rbdataBuffer
  221.  
  222.     lda obeof    ;How big the open eof is tells
  223.     ldx obeof+2    ;us how many bytes to request
  224.     sta rbrequestCount    ;for read.
  225.     stx rbrequestCount+2
  226.     _ReadGS readBlock
  227.     bcc ad
  228.     jsr doErrorWindow
  229.     brl disposeCloseUnlockExit
  230.  
  231. ad    _CloseGS closeBlock
  232.     bcc ae
  233.     jsr doErrorWindow
  234.     brl disposeUnlockExit
  235.  
  236. ae    pea refIsHandle*8+teDataIsTextBlock
  237.     pei theHndl+2
  238.     pei theHndl
  239.     lda #0
  240.     pha    ;NULL
  241.     pha
  242.     pha    ;0
  243.     pha    ;NULL
  244.     pha
  245.     pha    ;GetCtlHandleFromID    result space
  246.     pha
  247.     pha    ;FrontWindow result    space
  248.     pha
  249.     _FrontWindow
  250.     PushLong #MainWindowID
  251.     _GetCtlHandleFromID
  252.     _TESetText
  253.  
  254. disposeUnlockExit        ; 
  255.     pei theHndl+2    ;All done with this    handle.
  256.     pei theHndl    ;Dispose it, finish    up and leave.
  257.     _DisposeHandle
  258.     bra unlockExit
  259.  
  260. disposeCloseUnlockExit    ; 
  261.     pei theHndl+2    ;All done with this    handle.
  262.     pei theHndl
  263.     _DisposeHandle
  264.  
  265. closeUnlockExit    _CloseGS closeBlock    ;Close the file.
  266.  
  267. unlockExit    pei c1hndl+2    ;Unlock handle passed to us.
  268.     pei c1hndl
  269.     _HUnlock
  270.  
  271.     pla    ;Remove local variable space.
  272.     pla
  273.     pla
  274.     pla
  275.     pld    ;Restore directPage    register.
  276.     plx    ;Save return address.
  277.     pla    ;Remove passed parameters.
  278.     pla
  279.     phx    ;Restore return address and return.
  280.     rts
  281.  
  282. doErrorWindow    pha
  283.     ldx #0
  284.     phx
  285.     phx
  286.     phx
  287.     pha
  288.     _ErrorWindow
  289.     pla
  290.     rts
  291.  
  292. openBlock        ; 
  293. obpCount    DC.W 15
  294. obrefNum    DC.W 0
  295. obpathname    DC.L 0
  296. obrequestAccess    DC.W 0
  297. obresourceNumber    DC.W 0
  298. obaccess    DC.W 0
  299. obfileType    DC.W 0
  300. obauxType    DC.L 0
  301. obstorageType    DC.W 0
  302. obcreateDateTime    DS.B 8
  303. obmodDateTime    DS.B 8
  304. oboptionList    DC.L 0
  305. obeof    DC.L 0
  306. obblocksUsed    DC.L 0
  307. obresourceEOF    DC.L 0
  308. obresourceBlocks    DC.L 0
  309.  
  310. closeBlock        ; 
  311. clbpCount    DC.W 1
  312. clbrefNum    DC.W 0
  313.  
  314. readBlock        ; 
  315. rbpCount    DC.W 4
  316. rbrefNum    DC.W 0
  317. rbdataBuffer    DC.L 0
  318. rbrequestCount    DC.L 0
  319. rbtransferCount    DC.L 0
  320.  
  321.     ENDP
  322.  
  323. ***********************************************************************
  324. *
  325. * putWindowIntoFile
  326. *
  327. * This routine opens the specified file, writes the window contents.
  328. *
  329.     EXPORT putWindowIntoFile
  330. putWindowIntoFile    PROC
  331.     import userID
  332.  
  333.     DefineStack
  334.  
  335. theHndl    long    ;Must be at 1,s
  336. c1ptr    long
  337. totalSize    long
  338.  
  339. saveDPage    word
  340. returnAddr    word
  341.  
  342. c1hndl    long
  343.  
  344. ******************
  345.  
  346.     phd    ;Save directPage register.
  347.     pha    ;Make space for locals.
  348.     pha
  349.     pha
  350.     pha
  351.     pha
  352.     pha
  353.     tsc    ;Set directPage register.
  354.     tcd
  355.  
  356.     pei c1hndl+2    ;Lock down the passed handle.
  357.     pei c1hndl
  358.     _HLock
  359.  
  360.     ldy #2    ;Dereference the handle and skip
  361.     lda [c1hndl],y    ;the C1Output buffer size word.
  362.     tax
  363.     lda [c1hndl]
  364.     clc
  365.     adc #2
  366.     bcc aa
  367.     inx
  368. aa    sta c1ptr
  369.     stx c1ptr+2
  370.  
  371.     sta dbname    ;Destroy block pathname.
  372.     stx dbname+2
  373.     sta cbpathname    ;Create block pathname.
  374.     stx cbpathname+2
  375.     sta obpathname    ;Open block pathname.
  376.     stx obpathname+2
  377.     _DestroyGS destroyBlock ;Destroy the file always.
  378.     bcc ab
  379.     cmp #fileNotFound    ;It may have not been there.
  380.     beq ab
  381.     jsr doErrorWindow
  382.     brl unlockExit
  383.  
  384. ab    lda #$C3
  385.     sta cbaccess
  386.     lda #$04
  387.     sta cbfileType
  388.     lda #0
  389.     sta cbauxType
  390.     sta cbauxType+2
  391.     _CreateGS createBlock
  392.     bcc ac
  393.     jsr doErrorWindow
  394.     brl unlockExit
  395.  
  396. ac    lda #0
  397.     sta obrequestAccess
  398.     sta obresourceNumber
  399.     sta oboptionList
  400.     sta oboptionList+2
  401.     _OpenGS openBlock
  402.     bcc ad
  403.     pha    ;Keep error code.
  404.     _DestroyGS destroyBlock
  405.     pla
  406.     jsr doErrorWindow
  407.     brl unlockExit
  408.  
  409. ad    lda obrefNum
  410.     sta clbrefNum
  411.     sta wbrefNum
  412.  
  413.     PushLong #1
  414.     lda userID
  415.     pha
  416.     lda #0
  417.     pha
  418.     pha
  419.     pha
  420.     _NewHandle    ;Result in theHndl
  421.     bcc ae
  422.     pha    ;Keep error code.
  423.     _CloseGS closeBlock
  424.     _DestroyGS destroyBlock
  425.     pla
  426.     jsr doErrorWindow
  427.     brl unlockExit
  428.  
  429. ae    pha    ;Result space
  430.     pha
  431.     pea refIsHandle*8+teDataIsTextBlock
  432.     pei theHndl+2
  433.     pei theHndl
  434.     lda #0
  435.     pha    ;NULL
  436.     pha
  437.     pha    ;0
  438.     pha    ;NULL
  439.     pha
  440.     pha    ;Result space for GetCtlHandleFromID
  441.     pha
  442.     pha    ;Result space for FrontWindow
  443.     pha
  444.     _FrontWindow
  445.     PushLong #MainWindowID
  446.     _GetCtlHandleFromID
  447.     _TEGetText
  448.     plx
  449.     stx totalSize
  450.     plx
  451.     stx totalSize+2
  452.     bcc af
  453.     pha
  454.     _CloseGS closeBlock
  455.     _DestroyGS destroyBlock
  456.     pla
  457.     jsr doErrorWindow
  458.     brl disposeUnlockExit
  459.  
  460. af    pei theHndl+2
  461.     pei theHndl
  462.     _HLock
  463.  
  464.     ldy #2
  465.     lda [theHndl],y
  466.     sta wbdataBuffer+2
  467.     lda [theHndl]
  468.     sta wbdataBuffer
  469.     lda totalSize
  470.     ldx totalSize+2
  471.     sta wbrequestCount
  472.     stx wbrequestCount+2
  473.     _WriteGS writeBlock
  474.     bcc ag
  475.     pha
  476.     _CloseGS closeBlock
  477.     _DestroyGS destroyBlock
  478.     pla
  479.     jsr doErrorWindow
  480.     brl disposeUnlockExit
  481.  
  482. ag    _CloseGS closeBlock
  483.     bcc disposeUnlockExit
  484.     pha
  485.     _DestroyGS destroyBlock
  486.     pla
  487.     jsr doErrorWindow
  488.  
  489.  
  490. disposeUnlockExit        ; 
  491.     pei theHndl+2
  492.     pei theHndl
  493.     _DisposeHandle
  494.  
  495. unlockExit    pei c1hndl+2
  496.     pei c1hndl
  497.     _HUnlock
  498.  
  499.     pla    ;Remove local variable space.
  500.     pla
  501.     pla
  502.     pla
  503.     pla
  504.     pla
  505.     pld    ;Restore directPage    register.
  506.     plx    ;Save return address.
  507.     pla    ;Remove passed parameters.
  508.     pla
  509.     phx    ;Restore return address and return.
  510.     rts
  511.  
  512.  
  513. doErrorWindow    pha
  514.     ldx #0
  515.     phx
  516.     phx
  517.     phx
  518.     pha
  519.     _ErrorWindow
  520.     pla
  521.     rts
  522.  
  523.  
  524. destroyBlock        ; 
  525. dbpCount    DC.W 1
  526. dbname    DC.L 0
  527.  
  528. createBlock        ; 
  529. cbpCount    DC.W 4
  530. cbpathname    DC.L 0
  531. cbaccess    DC.W 0
  532. cbfileType    DC.W 0
  533. cbauxType    DC.L 0
  534.  
  535. openBlock        ; 
  536. obpCount    DC.W 15
  537. obrefNum    DC.W 0
  538. obpathname    DC.L 0
  539. obrequestAccess    DC.W 0
  540. obresourceNumber    DC.W 0
  541. obaccess    DC.W 0
  542. obfileType    DC.W 0
  543. obauxType    DC.L 0
  544. obstorageType    DC.W 0
  545. obcreateDateTime    DS.B 8
  546. obmodDateTime    DS.B 8
  547. oboptionList    DC.L 0
  548. obeof    DC.L 0
  549. obblocksUsed    DC.L 0
  550. obresourceEOF    DC.L 0
  551. obresourceBlocks    DC.L 0
  552.  
  553. closeBlock        ; 
  554. clbpCount    DC.W 1
  555. clbrefNum    DC.W 0
  556.  
  557. writeBlock        ; 
  558. wbpCount    DC.W 4
  559. wbrefNum    DC.W 0
  560. wbdataBuffer    DC.L 0
  561. wbrequestCount    DC.L 0
  562. wbtransferCount    DC.L 0
  563.  
  564.     ENDP
  565.  
  566. ***********************************************************************
  567. *
  568. * placeAndShowWindow
  569. *
  570. * This routine moves the specified window based on stagger count
  571. * and shows it.
  572. *
  573.     EXPORT placeAndShowWindow
  574. placeAndShowWindow    PROC
  575.     import staggerCount
  576.  
  577.     DefineStack
  578.  
  579. saveDPage    word
  580. returnAddr    word
  581.  
  582. wptr    long
  583.  
  584. ******************
  585.  
  586.     phd    ;Save directPage register.
  587.     tsc    ;Set directPage register.
  588.     tcd
  589.  
  590.     lda staggerCount
  591.     asl a
  592.     asl a
  593.     asl a
  594.     adc #8
  595.     pha
  596.     adc #20
  597.     pha
  598.     pei wptr+2
  599.     pei wptr
  600.     _MoveWindow
  601.  
  602.     lda staggerCount
  603.     inc a
  604.     and #$07
  605.     sta staggerCount
  606.  
  607.     pei wptr+2
  608.     pei wptr
  609.     _ShowWindow
  610.     pei wptr+2
  611.     pei wptr
  612.     _SelectWindow
  613.  
  614.     pld    ;Restore directPage    register.
  615.     plx    ;Save return address.
  616.     pla    ;Remove passed parameters.
  617.     pla
  618.     phx    ;Restore return address and return.
  619.     rts
  620.  
  621.     ENDP
  622.  
  623. ***********************************************************************
  624. *
  625. * doOpenWindow
  626. *
  627. * This routine either asks the user what file to open and opens it.
  628. *
  629.     EXPORT doOpenWindow
  630. doOpenWindow    PROC
  631.  
  632.     DefineStack
  633.  
  634. wptr    long    ;Must be at 1,s
  635. myReply    block oReplyRec2size
  636. pstr    long
  637.  
  638. stkFrameSize    EndLocals
  639.  
  640. saveDPage    word
  641. returnAddr    word
  642.  
  643. ******************
  644.  
  645.     phd    ;Save directPage register.
  646.     tsc
  647.     sec
  648.     sbc #stkFrameSize    ;Make space for locals.
  649.     tcs
  650.     tcd    ;Set directPage register.
  651.  
  652.     pea 1
  653.     _SFAllCaps
  654.  
  655.     lda #refIsNewHandle
  656.     sta myReply+onameRefDesc
  657.     sta myReply+opathRefDesc
  658.  
  659.     tsc    ;Calculate pointer to myReply.
  660.     clc
  661.     adc #myReply
  662.     tax
  663.     pea 10
  664.     pea 35
  665.     pea refIsPointer
  666.     PushLong #promptStr
  667.     lda #0
  668.     pha    ;NULL
  669.     pha
  670.     pha    ;NULL
  671.     pha
  672.     pha    ;Pointer to myReply
  673.     phx
  674.     _SFGetFile2
  675.     lda myReply+ogood
  676.     beq exit
  677.  
  678.     pei myReply+onameRef+2
  679.     pei myReply+onameRef
  680.     _HLock
  681.  
  682.     ldy #2
  683.     lda [myReply+onameRef],y
  684.     tax
  685.     lda [myReply+onameRef]
  686.     sta pstr
  687.     stx pstr+2
  688.     shortm
  689.     lda [pstr],y    ;2 in yreg.
  690.     iny
  691.     sta [pstr],y
  692.     longm
  693.     tya    ;3 in yreg.
  694.     clc
  695.     adc pstr
  696.     bcc aa
  697.     inx
  698.  
  699. aa    phx    ;Pointer to window title.
  700.     pha
  701.     pei myReply+opathRef+2
  702.     pei myReply+opathRef
  703.     PushLong #drawThisWindow
  704.     lda #0
  705.     pha
  706.     pha
  707.     pea refIsResource
  708.     PushLong #MainWindowID
  709.     pea rWindParam1
  710.     _NewWindow2
  711.  
  712.     pei myReply+onameRef+2
  713.     pei myReply+onameRef
  714.     _DisposeHandle
  715.  
  716.     pei wptr+2
  717.     pei wptr
  718.     jsr placeAndShowWindow
  719.  
  720.     pei myReply+opathRef+2
  721.     pei myReply+opathRef
  722.     jsr putFileIntoWindow
  723.  
  724. exit    tsc    ;Remove local space.
  725.     clc
  726.     adc #stkFrameSize
  727.     tcs
  728.     pld    ;Restore directPage    register.
  729.     rts
  730.  
  731. promptStr    str 'Pick a file, any file.'
  732.  
  733.     ENDP
  734.  
  735. ***********************************************************************
  736. *
  737. * doSaveAs
  738. *
  739. * This routine either saves the file in    the place indicated    by the user.
  740. *
  741.     EXPORT doSaveAs
  742. doSaveAs    PROC
  743.     import userID
  744.  
  745.     DefineStack
  746.  
  747. myReply    block oReplyRec2size
  748. wtitle    long
  749. pstr    long
  750. wtptr    long
  751. wthndl    long
  752. wtlen    word
  753. refCon    long
  754.  
  755. stkFrameSize    EndLocals
  756.  
  757. saveDPage    word
  758. returnAddr    word
  759.  
  760. ******************
  761.  
  762.     phd    ;Save directPage register.
  763.     tsc
  764.     sec
  765.     sbc #stkFrameSize    ;Make space for locals.
  766.     tcs
  767.     tcd    ;Set directPage register.
  768.  
  769.     pea 1
  770.     _SFAllCaps
  771.  
  772.     lda #refIsNewHandle
  773.     sta myReply+onameRefDesc
  774.     sta myReply+opathRefDesc
  775.  
  776.     pha    ;Point to the window title.
  777.     pha
  778.     pha
  779.     pha
  780.     _FrontWindow
  781.     jsr smartGetWTitle
  782.     pla
  783.     sta wtitle
  784.     pla
  785.     sta wtitle+2
  786.  
  787.     lda [wtitle]    ;How long is the title?
  788.     and #$FF
  789.     sta wtlen
  790.  
  791.     pha    ;Create a handle for the title
  792.     pha    ;that will be big enough for
  793.     pea 0    ;the text and a word length.
  794.     lda wtlen
  795.     clc
  796.     adc #2
  797.     pha
  798.     lda userID
  799.     pha
  800.     lda #0
  801.     pha
  802.     pha
  803.     pha
  804.     _NewHandle
  805.     pla
  806.     sta wthndl
  807.     pla
  808.     sta wthndl+2
  809.     bcc aa
  810.  
  811. aa    ldy #2    ;Point to this handle.
  812.     lda [wthndl],y
  813.     sta wtptr+2
  814.     lda [wthndl]
  815.     sta wtptr
  816.  
  817.     pha    ;Re-dereference the    window
  818.     pha    ;title pointer, since it may
  819.     pha    ;be stored in a handle, and the
  820.     pha    ;handle may have moved.
  821.     _FrontWindow
  822.     jsr smartGetWTitle
  823.     pla
  824.     sta wtitle
  825.     pla
  826.     sta wtitle+2
  827.  
  828.     lda wtitle    ;Point to the title, skipping the
  829.     ldx wtitle+2    ;length byte.
  830.     inc a
  831.     bne ab
  832.     inx
  833. ab    phx
  834.     pha
  835.     lda wtptr    ;Point to the handle created to
  836.     ldx wtptr+2    ;hold the title, skipping the
  837.     clc    ;length word.
  838.     adc #2
  839.     bcc ac
  840.     inx
  841. ac    phx
  842.     pha
  843.     pea 0    ;Push the number of    bytes to copy.
  844.     pei wtlen
  845.     _BlockMove
  846.  
  847.     lda wtlen    ;Store the length word in the
  848.     sta [wtptr]    ;beginning of the handle.
  849.  
  850.     pei wthndl+2    ;Lock the handle, since SFPutFile2
  851.     pei wthndl    ;may move things around.
  852.     _HLock
  853.  
  854.     tsc    ;Calculate pointer to myReply.
  855.     clc
  856.     adc #myReply
  857.     tax
  858.     pea 180
  859.     pea 35
  860.     pea refIsPointer
  861.     PushLong #promptPtr
  862.     pea refIsPointer
  863.     pei wtptr+2
  864.     pei wtptr
  865.     pea 0    ;Pointer to myReply.
  866.     phx
  867.     _SFPutFile2
  868.  
  869.     pei wthndl+2    ;We are done with the window title.
  870.     pei wthndl
  871.     _DisposeHandle
  872.  
  873.     lda myReply+ogood    ;See if the user clicked cancel.
  874.     beq exit
  875.  
  876.     pha    ;We may have a handle in the refCon.
  877.     pha    ;If we do, then we need to dispose it.
  878.     pha
  879.     pha
  880.     _FrontWindow
  881.     _GetWRefCon
  882.     pla
  883.     sta refCon
  884.     pla
  885.     sta refCon+2
  886.     ora refCon
  887.     beq ad
  888.     pei refCon+2
  889.     pei refCon
  890.     _DisposeHandle
  891.  
  892. ad    pei myReply+opathRef+2 ;This is the new    handle for
  893.     pei myReply+opathRef ;the refCon.
  894.     pha
  895.     pha
  896.     _FrontWindow
  897.     _SetWRefCon
  898.  
  899.     ldy #2    ;We have a handle that is a
  900.     lda [myReply+onameRef],y ;C1Output string.  We want this
  901.     tax    ;to be a pascal string.  This
  902.     lda [myReply+onameRef] ;is accomplished    by moving byte
  903.     sta pstr    ;2 to byte 3, and then pointing
  904.     stx pstr+2    ;3 bytes into the handle.
  905.     shortm
  906.     lda [pstr],y    ;2 in yreg.
  907.     iny
  908.     sta [pstr],y
  909.     longm
  910.     tya
  911.     clc
  912.     adc pstr    ;3 in yreg.
  913.     bcc ae
  914.     inx
  915. ae    phx
  916.     pha
  917.     pha
  918.     pha
  919.     _FrontWindow
  920.     _SetWTitle
  921.  
  922.     pei myReply+onameRef+2 ;We are done with the name now.
  923.     pei myReply+onameRef
  924.     _DisposeHandle
  925.  
  926.     pei myReply+opathRef+2
  927.     pei myReply+opathRef
  928.     jsr putWindowIntoFile
  929.  
  930. exit    tsc    ;Remove local space.
  931.     clc
  932.     adc #stkFrameSize
  933.     tcs
  934.     pld    ;Restore directPage    register.
  935.     rts
  936.  
  937. promptPtr    str 'Give it a name, any name.'
  938.  
  939.     ENDP
  940.  
  941. ***********************************************************************
  942. *
  943. * doSave
  944. *
  945. * This routine either saves the file (unless it is new then    it does a save 
  946. * as).
  947. *
  948.     EXPORT doSave
  949. doSave    PROC
  950.  
  951.     DefineStack
  952.  
  953. wptr    long    ;Must be at 1,s
  954. refCon    long
  955.  
  956. saveDPage    word
  957. returnAddr    word
  958.  
  959. ******************
  960.  
  961.     phd    ;Save directPage register.
  962.     pha    ;Make space for locals.
  963.     pha
  964.     pha
  965.     pha
  966.     tsc    ;Set directPage register.
  967.     tcd
  968.  
  969.     _FrontWindow    ;Get the refCon.
  970.     pha
  971.     pha
  972.     pei wptr+2
  973.     pei wptr
  974.     _GetWRefCon
  975.     pla
  976.     sta refCon
  977.     pla
  978.     sta refCon+2
  979.     ora refCon    ;If the refCon is not NULL, then
  980.     bne aa    ;we already have a name for this file.
  981.     jsr doSaveAs    ;We don't have a name yet, so do
  982.     bra exit    ;a save as.
  983.  
  984. aa    pei refCon+2    ;We have a name, so    go for it.
  985.     pei refCon
  986.     jsr putWindowIntoFile
  987.  
  988. exit    plx
  989.     pla    ;Remove local space
  990.     pla
  991.     pla
  992.     pla
  993.     pld    ;Restore directPage    register.
  994.     phx
  995.     rts
  996.  
  997.     ENDP
  998.  
  999. ***********************************************************************
  1000. *
  1001. * NewWindow
  1002. *
  1003. * This routine opens a new untitled window.
  1004. *
  1005.     EXPORT doNewWindow
  1006. doNewWindow    PROC
  1007.  
  1008.     pha    ;Result space
  1009.     pha
  1010.     PushLong #promptPtr    ;Window title
  1011.     ldx #0
  1012.     phx    ;NULL
  1013.     phx
  1014.     PushLong #drawThisWindow
  1015.     phx    ;NULL
  1016.     phx
  1017.     pea refIsResource
  1018.     PushLong #MainWindowID
  1019.     pea rWindParam1
  1020.     _NewWindow2
  1021.  
  1022.     jsr placeAndShowWindow ;Uses above result space
  1023.     rts
  1024.  
  1025. promptPtr    str 'Untitled'
  1026.  
  1027.     ENDP
  1028.  
  1029. ***********************************************************************
  1030. *
  1031. * SetUpWindows
  1032. *
  1033. * Sets up WindowList record for use through out the program.
  1034. *
  1035.     EXPORT setupWindows
  1036. setupWindows    PROC
  1037.  
  1038.     jsr doNewWindow
  1039.     rts
  1040.  
  1041.     ENDP
  1042.  
  1043.     END
  1044.